-
Notifications
You must be signed in to change notification settings - Fork 38.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bandwidth: use regexp to handle tc output and add IPv6 support #83572
Conversation
Hi @chendotjs. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @dcbw @danwinship |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely like the idea
pkg/util/bandwidth/linux.go
Outdated
// expected tc line: | ||
// class htb 1:1 root prio 0 rate 1000Kbit ceil 1000Kbit burst 1600b cburst 1600b | ||
if len(parts) != 14 { | ||
return -1, fmt.Errorf("unexpected output from tc: %s (%v)", scanner.Text(), parts) | ||
classShowMatcher := regexp.MustCompile(`class\shtb\s(1:\d+)\sroot.*rate\s`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you matching the "root.*rate
" part too? Does that avoid some false positive? (If so maybe update the comment to indicate the kind of line you're trying to avoid matching too.)
Also, I'm not sure that using "\s
" rather than just "
" makes this any more generic/future-proof, and it makes it harder to read... (That applies throughout the patch.)
Also, you could make all of the MustCompile
regexes be top-level variables so they only get compiled once rather than getting recompiled every time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the code uses command like tc class add dev xxx parent 1: classid 1:x htb rate 1kbit
to add a new class where rate
is an explicit parameter, so "root.*rate
" ought to be matched explicitly. This is my primitive idea.
Other advice really make sense, thanks
pkg/util/bandwidth/linux.go
Outdated
// expected tc line: | ||
// match <cidr> at <number> | ||
if len(parts) != 4 { | ||
return nil, fmt.Errorf("unexpected output: %v", parts) | ||
cidrMatcher := regexp.MustCompile(`match\s([0-9a-f]{8}\/[[0-9a-f]{8}).*\s(\d+)`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is really an improvement over the old code. Also, it only handles IPv4 (the two hex strings are {32}
, not {8}
for IPv6; perhaps the test case should be updated for that). Also, there's no need to put ()
s around the \d+
since you're not using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently IPv6 is not yet supported I suppose? Because the code uses command like tc filter add dev xxx protocol ip parent 1:0 prio 1 u32 match ip dst 1.2.3.4/32 flowid 1:2
, the SELECTOR after match
is ip
, not ip6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah... TestHexCIDR
and TestAsciiCIDR
test IPv6 addresses and the old code would have matched either IPv4 or IPv6 so I assumed we cared. If not then I guess someone will fix this when they add IPv6 support here. (Although I don't know if anyone realized that the bandwidth code doesn't currently support IPv6. @khenidak do you know if this is being tracked?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm quite sure that IPv6 is not supported currently and I'll fix it.
7e204f5
to
1749e71
Compare
/ok-to-test |
/remove-priority critical-urgent |
@MrHohn @freehan @chendotjs We are fast approaching code freeze on 11/14. Hopefully we can get this in 1.17? |
Circling back on this @chendotjs @MrHohn @freehan, code freeze is 11/14 and by 5 pm pst I need to make the call if this gets moved out of this milestone. |
I have had no response to this and code freeze is tomorrow. I have to move this to milestone v1.18 |
/milestone v1.18 |
@chendotjs can you rebase to fix the conflict? thanks! |
@dcbw commits have been rebased and squashed. |
Hello @danwinship and @dcbw, |
Hello @danwinship and @dcbw, cc @kubernetes/sig-network-pr-reviews |
The IPv6 support here seems extremely complicated and I feel like it ought to be possible to simplify it a lot. I would recommend just reverting back to the original version of the PR, addressing the non-IPv6-related comments, and resubmitting that, and then we can think about IPv6 support again later. |
fix newly-added 'chain N' output from 'tc filter show dev XXX'
Truly thanks for your practical advice ! @danwinship |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: chendotjs, danwinship The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
What type of PR is this?
/kind bug
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #76064
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: